package com.tanfuqi.sicent.server.controller

import com.tanfuqi.sicent.protocol.message.ActiveInfo
import com.tanfuqi.sicent.protocol.message.Message
import com.tanfuqi.sicent.server.filter.sent
import io.swagger.annotations.ApiOperation
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RestController
class ActiveController:BaseController() {


    @Suppress("NAME_SHADOWING")
    @ApiOperation(value = "激活会员")
    @PatchMapping(value = ["/shop/{shopId}/member/{cardId}/active"])
    fun active(@PathVariable shopId: String, @PathVariable cardId: String,
               @RequestBody activeInfo: ActiveInfo): Mono<Any> =
            Mono.justOrEmpty(activeInfo).doOnSuccess { it.cardId=cardId }.flatMap { activeInfo ->
                session(shopId).sent(Message(0x8044, body = activeInfo)).map { it.body }

            }

}